package com.knife.file.api.controller.v1;

import com.knife.common.utils.Results;
import com.knife.file.app.KnifeFileInfoService;
import com.knife.file.domain.entity.KnifeFileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件模块controller
 *
 * @author： 76875
 * @date： 2022/4/7 星期四 11:49
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RestController
@RequestMapping("/v1/{organizationId}/file")
public class KnifeFileController {

    @Autowired
    private KnifeFileInfoService knifeFileInfoService;


    /**
     * 基于Multipart上传文件
     *
     * @param organizationId 租户ID
     * @param bucketName     桶名
     * @param directory      上传目录
     * @param fileName       文件名
     * @param docType        默认类型 1:固定,0:不固定
     * @param storageCode    存储配置编码
     * @param multipartFile  上传文件
     * @return 文件url
     */
    @PostMapping("/multipart")
    public ResponseEntity<KnifeFileInfo> uploadFile(
            @PathVariable Long organizationId,
            @RequestParam("bucketName") String bucketName,
            @RequestParam(value = "directory", required = false) String directory,
            @RequestParam(value = "fileName", required = false) String fileName,
            @RequestParam(value = "docType", defaultValue = "0") Integer docType,
            @RequestParam(value = "storageCode", required = false) String storageCode,
            @RequestParam("file") MultipartFile multipartFile) {
        return Results.success(knifeFileInfoService.uploadMultipart(organizationId, bucketName, null, directory, fileName, docType, storageCode, multipartFile));
    }

}
